package com.wc.codeforces.排序.Progressive_Square;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/6/14 11:05
 * @description https://codeforces.com/problemset/problem/1955/B
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 510, len;
    static int[][] a = new int[N][N];
    static int[] b = new int[N * N], nums = new int[N * N];
    static int n, c, d;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            c = sc.nextInt();
            d = sc.nextInt();
            for (int i = 1; i <= n * n; i++) b[i] = sc.nextInt();
            Arrays.sort(b, 1, n * n + 1);
            len = 0;
            for (int i = 1; i <= n * n; i++) {
                if (b[i] != b[i - 1]) {
                    b[++len] = b[i];
                    nums[len] = 1;
                } else nums[len]++;
            }
            a[1][1] = b[1];
            int num = a[1][1];
            boolean res = true;
            // 检查第一列
            for (int i = 2; i <= n; i++) {
                num += c;
                int id = check(num);
                if (id != -1 && nums[id] > 0) {
                    nums[id]--;
                    a[i][1] = b[id];
                } else {
                    res = false;
                }
            }
            if (res) {
                // 检查每一行,就好了
                for (int i = 1; i <= n; i++) {
                    for (int j = 2; j <= n; j++) {
                        int id = check(a[i][j - 1] + d);
                        if (id != -1 && nums[id] > 0) {
                            nums[id]--;
                            a[i][j] = b[id];
                        } else {
                            res = false;
                            break;
                        }
                    }
                    if (!res) break;
                }
            }
            out.println(res ? "YES" : "NO");
        }
        out.flush();
    }

    static int check(int x) {
        int l = 1, r = len;
        while (l < r) {
            int mid = l + r >> 1;
            if (b[mid] >= x) r = mid;
            else l = mid + 1;
        }
        return b[l] == x ? l : -1;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
